package edu.nf.waimai.service.rider.impl;

import edu.nf.util.sms.SMSUtil;
import edu.nf.waimai.dao.rider.impl.RiderDAOImpl;
import edu.nf.waimai.model.rider.Rider;
import edu.nf.waimai.service.exception.LoginException;
import edu.nf.waimai.service.rider.RiderService;

/**
 * @Date 2023-06-20
 * @Author qiu
 * 骑手业务实现类
 */
public class RiderServiceImpl implements RiderService {
    /**
     * 骑手登录
     *
     * @param
     * @return
     */
    @Override
    public Rider loginRider(String key, String phone) {

        // 判断输入的验证码和生成的验证码是否一致
        String send = new SMSUtil().send(phone);

        if (key.trim().equals(send)){
            Rider rider = new RiderDAOImpl().loginRider(phone);
            if (phone.equals(rider.getRiderPhone())) {
                return rider;
            }
            throw new LoginException(500, "账号或密码错误");
        }else{
            throw new RuntimeException("验证码错误");
        }



    }


    /**
     * 骑手注册
     *
     * @param riderName  姓名
     * @param riderPhone 电话
     * @param riderType  类型
     * @param
     * @return
     */
    @Override
    public Object registerRider(String riderName, String riderPhone, String riderType) {

        Object row = new RiderDAOImpl().registerRider(riderName,riderPhone,riderType);

        // 判断输入的验证码和生成的验证码是否一致
//        String send = new SMSUtil().send(riderPhone);
//        if (key.trim().equals(send)) {
//            row = new RiderDAOImpl().registerRider(riderName, riderPhone, riderType);
//            return row;
//        }
//        try {
//            throw new CodeException("验证码错误");
//        } catch (CodeException e) {
//            throw new RuntimeException(e);
//        }

        return row;

    }
}
